local skill = fk.CreateSkill {
  name = "#pegasus__catapult_skill",
  attached_equip = "pegasus__catapult",
}

skill:addEffect(fk.PreCardEffect, {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skill.name) and player == target and data.card.trueName == "slash"
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    data.nullified = true
    local room = player.room
    if #Card:getIdList(data.card) > 0 and room:getCardArea(data.card) then
      room:obtainCard(data.to, data.card, true, fk.ReasonGive, player, "pegasus__catapult")
    end
    if data.to:isNude() then return end

    local cards = room:askToChooseCards(player, {
      target = data.to,
      flag = "he",
      max = 3,
      min = 0,
      skill_name = "pegasus__catapult",
    })
    if #cards == 0 then return end

    room:throwCard(cards, "pegasus__catapult", data.to, player)
    if player.dead or data.to.dead then return end

    cards = table.map(cards, function(c) return Fk:getCardById(c).trueName end)
    if table.find(cards, function (n) return n == "slash" end) and not table.find(cards, function (n) return n == "jink" end) then
      room:damage{
        damage = 1,
        to = data.to,
        from = player,
        skillName = "pegasus__catapult",
        card = data.card,
      }
    end
  end
})

return skill